package tech.aistar.Code;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;

import java.util.HashMap;
import java.util.Map;

public class IdCardCheck {
    public static JSONObject IdCardCheck(String certificationName, String cardId) {
        String host = "https://zidv2.market.alicloudapi.com";
        String path = "/idcard/VerifyIdcardv2";
        String method = "GET";
        String appcode = "8098ba987a8242d8be3eafa8ee88c366";//在阿里云上面购买实名认证2要素接口以后就可以获得
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, String> querys = new HashMap<String, String>();
        querys.put("cardNo", cardId);
        querys.put("realName", certificationName);
        HttpResponse response = null;
        try {
            /**
             * 重要提示如下:
             * HttpUtils请从
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/
             src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
             * 下载
             *
             * 相应的依赖请参照
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
             */
            response =  HttpUtils.doGet(host, path, method, headers, querys);
            JSONObject jsonObject = JSON.parseObject(EntityUtils.toString(response.getEntity()));
            JSONObject json = JSONObject.parseObject(String.valueOf(jsonObject));
            JSONObject result= (JSONObject) json.get("result");
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new JSONObject();
    }

//    public static void main(String[] args) {
//        IdCardCheck.IdCardCheck("左帅", "32072419900609455X");
//
//        System.out.println(IdCardCheck.IdCardCheck("左帅", "32072419900609455X"));
//    }
}

